package com.example.basicstudyka

import android.os.Bundle
import com.google.android.material.snackbar.Snackbar
import androidx.appcompat.app.AppCompatActivity
import androidx.navigation.findNavController
import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.navigateUp
import androidx.navigation.ui.setupActionBarWithNavController
import android.view.Menu
import android.view.MenuItem
import androidx.appcompat.app.AlertDialog
import com.example.basicstudyka.databinding.ActivityMainBinding

class MainActivity : AppCompatActivity() {

    private lateinit var appBarConfiguration: AppBarConfiguration
    private lateinit var binding: ActivityMainBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        // 视图绑定
        binding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(binding.root)

        setSupportActionBar(binding.toolbar)

//        val navController = findNavController(R.id.nav_host_fragment_content_main)
//        appBarConfiguration = AppBarConfiguration(navController.graph)
//        setupActionBarWithNavController(navController, appBarConfiguration)

        binding.fab.setOnClickListener { view ->
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                .setAction("Action", null).show()
        }

        var count:Int = 0
        binding.changeBtn.setOnClickListener { view ->
            var i:Int = 0
            var arr1:IntArray = intArrayOf(1,2,3)
            var arr2:Array<String> = arrayOf("1", "2")
            val set1:Set<String> = setOf("haha", "hehe")
            var set2:MutableSet<Array<Int>> = mutableSetOf(arrayOf(1,2,3))
            val list1:List<String> = listOf("666", "777", "888")
            var list2:MutableList<Array<Boolean>> = mutableListOf(arrayOf(true, false), arrayOf(true, false))
            val map1:Map<String, String> = mapOf("key1" to "value1", Pair("key2", "value2"))
            var map2:MutableMap<String, Array<Int>> = mutableMapOf("key1" to arrayOf(1,2), Pair("key2", arrayOf(5,6)))
//            binding.changeText.text = "show me the money${'$'}\$：$i"
            binding.changeText.text = when(count){
                1,3,5,7,9 -> "666"
                in 13..19 -> "777"
                !in 6..10 -> "888"
                else -> "show me the money${'$'}\$：$i"
            }
            count = (count + 1) % 20
            copyWhenGenerator(listOf<String>('1','2','3'), '2')
        }
    }

    override fun onCreateOptionsMenu(menu: Menu): Boolean {
        // Inflate the menu; this adds items to the action bar if it is present.
        menuInflater.inflate(R.menu.menu_main, menu)
        return true
    }

    override fun onOptionsItemSelected(item: MenuItem): Boolean {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        return when (item.itemId) {
            R.id.action_settings -> true
            else -> super.onOptionsItemSelected(item)
        }
    }

    override fun onSupportNavigateUp(): Boolean {
        val navController = findNavController(R.id.nav_host_fragment_content_main)
        return navController.navigateUp(appBarConfiguration)
                || super.onSupportNavigateUp()
    }
}
fun <T> copyWhenGenerator(list: List<T>, threshold: T): List<String>
    where T: CharSequence,
          T: Comparable<T> {
              return list.filter { it > threshold }.map { it.toString() }
}